{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from gs_quant.session import Environment, GsSession\n",
    "from gs_quant.instrument import FXForward\n",
    "from gs_quant.markets.portfolio import Portfolio\n",
    "from datetime import date\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# external users should substitute their client id and secret; please skip this step if using internal jupyterhub\n",
    "GsSession.use(Environment.PROD, client_id=None, client_secret=None, scopes=('run_analytics',))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# get list of properties of an fx forward\n",
    "FXForward.properties()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# in this example we will construct and price a portfolio of FXForwards\n",
    "fx_fwds = Portfolio()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# pair is the forward's currency pair.  It a string of two ccy iso codes, optionally separated with a space (' ')\n",
    "# The first currency is the base currency and the second is the quote currency\n",
    "\n",
    "# In this case, base currency is 'EUR' and quote currency is 'GBP'. \n",
    "fx_fwds.append(FXForward(pair='EUR GBP', settlement_date='3y'))\n",
    "fx_fwds.append(FXForward(pair='EURGBP', settlement_date='3y'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# notional_amount is the quantity of the base currency to be exchanged in the future; it can be a string (eg: '100mm')\n",
    "# or a double (10e8)\n",
    "\n",
    "# For these two forwards - some amount of GBP will be exchanged for 100mm EUR at a future date\n",
    "fx_fwds.append(FXForward(pair='EURGBP', notional_amount='100m', settlement_date='3y'))\n",
    "fx_fwds.append(FXForward(pair='EURGBP', notional_amount=10e8, settlement_date='3y'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# settlement_date is the contract settlement date. It can either be a date or string\n",
    "fx_fwds.append(FXForward(settlement_date='3y'))\n",
    "fx_fwds.append(FXForward(settlement_date=date(2023,9,25)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# forward rate is the exchange rate which will be used on the settlement date.  It is a double.  \n",
    "# If not set then it will resolve to the fair fx fwd rate\n",
    "\n",
    "# In this example, the individual long the FXForward will pay 95mm GBP in exchange for 100mm EUR on the settlement date   \n",
    "fx_fwds.append(FXForward(pair='EURGBP', notional_amount=10e8, forward_rate=.95, settlement_date='3y'))\n",
    "\n",
    "# If not set then it will resolve to the fair fx fwd rate\n",
    "fx_fwds.append(FXForward(pair='EURGBP', notional_amount=10e8, settlement_date='3y'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.DataFrame(fx_fwds.price())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
